import java.util.ArrayList;
import java.util.Scanner;

/**
 * This classes contains functionality for finding all the
 * palindroms from the given string and for outputting them (or any other lines)
 * into System.out stream.
 * 
 * @author Andrew Onischuk (Empower)
 *
 */
public class PalindomFinder {

	/**
	 * In this method (it is executed on programs startup) we use the facilities of
	 * Scanner and PalindromFinder classes to read the line from the console, to
	 * find palindromes in it and to write the results to System.out stream.
	 * 
	 * @param args arguments passed from the command line
	 */
	public static void main(String[] args) {      
		Scanner scanner = new Scanner(System.in);
		PalindomFinder palindomFinder = new PalindomFinder();
		
		try{
			palindomFinder.printLines(palindomFinder.getAllPalindromes(scanner.nextLine()));
		}catch(IllegalArgumentException ex){
			System.err.println(ex.getMessage());
		}finally{
			scanner.close();
		}
	}
	
	/**
	 * Returns all the sublines, which are palindomes and have
	 * length > 2
	 * 
	 * @param source this is the string to look up for palindromes it 
	 * should be longer then 2 symbols or else IllegalArgumentException is thrown
	 * @return all the palindromes with length >2 has been found
	 */
	public ArrayList<String> getAllPalindromes(String source) {
		if(source.length()<3)
			throw new IllegalArgumentException("The string is too short!");
		
		ArrayList<String> palindromes = new ArrayList<String>();
		
		for(int i=3;i<=source.length();i++){
			palindromes.addAll(getPalindromesByLength(source, i));
		}
		
		return palindromes;
	}
	
	/**
	 * Returns ArrayList of all the palindromes of the given length
	 * 
	 * @param source String where palindromes are looked for
	 * @param length length of the palidromes are looked for
	 * @return ArrayList of all the palindromes we found
	 */
	private ArrayList<String> getPalindromesByLength(String source, int length){
		ArrayList<String> palindromes = new ArrayList<String>();
		
		for(int start=0; start <= source.length()-length; start++){
			
			String currentString = source.substring(start,start+length);
			if(isPalindrome(currentString)){
				palindromes.add(currentString);
			}
			
		}
		return palindromes;
	}
	
	/**
	 * This method checks whether input text is palindrome
	 * 
	 * @param text text to check
	 * @return returns true if input string is palindrome, otherwise false
	 */
	private boolean isPalindrome(String text){
		return (text.equals(new StringBuilder(text).reverse().toString()));
	}
	
	/**
	 * Outputs ArrayList into a System.out stream.
	 * 
	 * @param palindromes return
	 */
	private void printLines(ArrayList<String> strings){
		for(String string: strings){
			System.out.println(string);
		}
	}
}
